﻿using System;
using System.Drawing;
using System.Windows.Forms;
using WorkbookDesigner.Annotations;

namespace WorkbookDesigner.Addons.SpreadsheetEditor.UI
{
    public partial class UcBasePrompt : UserControl
    {

        public UcBasePrompt()
        {
            InitializeComponent();
        }


        //private string _pText;
        //private string _pValue;
        //private bool _adaptable;

        /// <summary>
        /// 标签文本
        /// </summary>
        public string PText
        {
            get
            {
                return labelText.Text;
            }
            set
            {
                labelText.Text = value;
                ResizeControl();
            }
        }
        /// <summary>
        /// 文本框中的值
        /// </summary>
        public string PValue
        {
            get { return textBoxValue.Text; }
            set
            {
                textBoxValue.Text = value;
            }
        }
        /// <summary>
        /// 勾选框的值
        /// </summary>
        public bool Adaptable
        {
            get
            {
                return checkBoxToModify.Checked;
            }
            set
            {
                checkBoxToModify.Checked = value;
            }
        }

        public override string ToString()
        {
            return PValue;
        }

        [NotifyPropertyChangedInvocator]

        private void UcBasePrompt_Load(object sender, EventArgs e)
        {
            ResizeControl();
            //textBoxValue.DataBindings.Add(new Binding("Text", this, "PValue", false, DataSourceUpdateMode.OnPropertyChanged));
            //labelText.DataBindings.Add(new Binding("Text", this, "PValue", false, DataSourceUpdateMode.OnPropertyChanged));
            //checkBoxToModify.DataBindings.Add(new Binding("Checked", this, "Adaptable", false, DataSourceUpdateMode.OnPropertyChanged));
        }

        private void ResizeControl()
        {
            int w = this.Width - checkBoxToModify.Width - /*labelText.Width*/80 - labelText.Margin.Horizontal - textBoxValue.Margin.Horizontal - checkBoxToModify.Margin.Horizontal;
            textBoxValue.Width = w;
            textBoxValue.Location = new Point(labelText.Margin.Horizontal + /*labelText.Width*/80 + textBoxValue.Margin.Left, textBoxValue.Location.Y);
            this.Refresh();
        }
    }
}
